package com.dh.project.controller;

import com.dh.project.model.LableInfo;
import com.dh.project.model.ServiceProject;
import com.dh.project.other.ModelRes;
import com.dh.project.service.LableInfoService;
import com.dh.project.service.ServiceProjectService;
import com.dh.project.view.LableDetailView;
import com.dh.project.view.LableView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by admin on 2017/4/25.
 */
@Controller
public class ProductController {

    private ServiceProjectService serviceProjectService;

    private LableInfoService lableInfoService;

    @Autowired
    public ProductController(ServiceProjectService serviceProjectService,LableInfoService lableInfoService){
        this.serviceProjectService = serviceProjectService;
        this.lableInfoService = lableInfoService;
    }

    /**
     * 查询标签
     * @param class_id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "selectLableInfo",produces = "text/html;charset=utf-8")
    public Object selectLableInfo(int class_id){
        Map map = new HashMap();
        map.put("lable_class_one",class_id);
        List<LableInfo> lableInfoList = lableInfoService.selectByMap(map);

        LableView lableView = new LableView();
        lableView.getFamilyType().getBrandType().setTitle("品牌");
        lableView.getFamilyType().getMaterialType().setTitle("耗材");
        lableView.getFamilyType().getSpecificationType().setTitle("规格");
        lableView.getCommercialList().getBrandType().setTitle("品牌");
        lableView.getCommercialList().getMaterialType().setTitle("耗材");
        lableView.getCommercialList().getSpecificationType().setTitle("规格");
        for (int i = 0; i < lableInfoList.size(); i++) {
            LableDetailView lableDetailView = getLableDetail(lableInfoList.get(i));
            if (lableInfoList.get(i).getLable_class_two() == 1){ //民用
                if (lableInfoList.get(i).getLable_type() == 1){ //品牌
                    lableView.getFamilyType().getBrandType().getList().add(lableDetailView);
                }else if (lableInfoList.get(i).getLable_type() == 2){ //规格
                    lableView.getFamilyType().getSpecificationType().getList().add(lableDetailView);
                }else if (lableInfoList.get(i).getLable_type() == 3){ //部件
                    lableView.getFamilyType().getMaterialType().getList().add(lableDetailView);
                }
            }else {//商用
                if (lableInfoList.get(i).getLable_type() == 1){ //品牌
                    lableView.getCommercialList().getBrandType().getList().add(lableDetailView);
                }else if (lableInfoList.get(i).getLable_type() == 2){ //规格
                    lableView.getCommercialList().getSpecificationType().getList().add(lableDetailView);
                }else if (lableInfoList.get(i).getLable_type() == 3){ //部件
                    lableView.getCommercialList().getMaterialType().getList().add(lableDetailView);
                }
            }
        }
        return new ModelRes(ModelRes.Status.SUCCESS,"查询成功！",lableView);
    }


    public LableDetailView getLableDetail(LableInfo lableInfo){
        LableDetailView lableDetailView = new LableDetailView();
        lableDetailView.setLableId(lableInfo.getLable_id());
        lableDetailView.setLableName(lableInfo.getLable_name());
        lableDetailView.setModifytime(lableInfo.getModifytime());
        return lableDetailView;
    }

    /**
     * 产品列表
     * @param serviceProject
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "selectServiceProjectList",produces = "text/html;charset=utf-8")
    public Object selectServiceProjectList(ServiceProject serviceProject){
        //查询产品内容
        Map map = new HashMap();
        if (null != serviceProject.getService_class() && serviceProject.getService_class() != 0){
            map.put("service_class",serviceProject.getService_class());//分类
        }
        if (null != serviceProject.getService_brand() && serviceProject.getService_brand() != 0){
            map.put("service_brand",serviceProject.getService_brand());//品牌
        }
        if (null != serviceProject.getService_kind() && serviceProject.getService_kind() != 0){
            map.put("service_kind",serviceProject.getService_kind());//种类
        }
        if (null != serviceProject.getService_standard() && serviceProject.getService_standard() != 0){
            map.put("service_standard",serviceProject.getService_standard());//规格
        }
        if (null != serviceProject.getService_assembly() && serviceProject.getService_assembly() != 0){
            map.put("service_assembly",serviceProject.getService_assembly());//部件
        }
        if (null != serviceProject.getService_back() && serviceProject.getService_back() != "" ){
            map.put("service_back",serviceProject.getService_back()); //型号
        }
        List<ServiceProject> serviceProjectList = serviceProjectService.selectByMap(map);
        return new ModelRes(serviceProjectList);
    }

    /**
     * 查询产品详情
     * @param service_id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "selectServiceProjectById",produces = "text/html;charset=utf-8")
    public Object selectServiceProjectById(int service_id){
        ServiceProject serviceProject = serviceProjectService.selectById(Long.valueOf(service_id));
        return new ModelRes(ModelRes.Status.SUCCESS,"查询成功",serviceProject);
    }

    /**
     * 维修价格列表
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "selectMaintainList",produces = "text/html;charset=utf-8")
    public Object selectMaintainList(int order_type){
        Map map = new HashMap();
        map.put("service_class",7);
        map.put("service_kind",order_type);
        List<ServiceProject> serviceProjects = serviceProjectService.selectByMap(map);
        return new ModelRes(serviceProjects);
    }

    /**
     * 维修价格详情
     * @param service_id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "selectMaintainById",produces = "text/html;charset=utf-8")
    public Object selectMaintainById(int service_id){
        ServiceProject serviceProject = serviceProjectService.selectById(Long.valueOf(service_id));
        return new ModelRes(ModelRes.Status.SUCCESS,"查询成功",serviceProject);
    }


}
